<?php

/**
 * ProductCategory filter form base class.
 *
 * @package    erpcrm
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormFilterGeneratedTemplate.php 24171 2009-11-19 16:37:50Z Kris.Wallsmith $
 */
abstract class BaseProductCategoryFormFilter extends BaseFormFilterPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'name'                          => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'level_number'                  => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'alias'                         => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'product_category_product_list' => new sfWidgetFormPropelChoice(array('model' => 'Product', 'add_empty' => true)),
    ));

    $this->setValidators(array(
      'name'                          => new sfValidatorPass(array('required' => false)),
      'level_number'                  => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'alias'                         => new sfValidatorPass(array('required' => false)),
      'product_category_product_list' => new sfValidatorPropelChoice(array('model' => 'Product', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('product_category_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function addProductCategoryProductListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(ProductCategoryProductPeer::CATEGORY_IDEN, ProductCategoryPeer::IDEN);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(ProductCategoryProductPeer::PRODUCT_IDEN, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(ProductCategoryProductPeer::PRODUCT_IDEN, $value));
    }

    $criteria->add($criterion);
  }

  public function getModelName()
  {
    return 'ProductCategory';
  }

  public function getFields()
  {
    return array(
      'iden'                          => 'Text',
      'name'                          => 'Text',
      'level_number'                  => 'Number',
      'alias'                         => 'Text',
      'product_category_product_list' => 'ManyKey',
    );
  }
}
